// This is the main DLL file.

#include "FaceDetect.h"
#include <vector>

using namespace std;

FaceDetect::FaceDetect(vector<IplImage*> inputImage):inputImage(inputImage)
{
	classifierName = "classifier.xml";
	for(vector<IplImage*>::iterator iter = inputImage.begin(); iter != inputImage.end(); iter++)
	{
		FaceFinder *finder = new FaceFinder(classifierName.c_str(),*iter);
		finder->GetFaceChoped();		
		faceList.push_back(finder->getFaces());
		waitKey(0);
	}
}

IplImage* FaceDetect::compare(IplImage *image)
{
	FaceFinder *finder = new FaceFinder(classifierName.c_str(),image);
	finder->GetFaceChoped();
	vector<IplImage*> face = finder->getFaces();

	LbpManager *manager = new LbpManager();
	manager->Init();

	double min = 10000.0;
	int targetIndex = -1;
	for(int i = 0; i < faceList.size(); i++)
	{
		double result = manager->compare(faceList[i][0],face[0]);
		if(result < min)
		{
			min = result;
			targetIndex = i;
		}
	}
	cvDestroyWindow("result");

	return inputImage[targetIndex];
}
